package com.iims.finance.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.iims.common.annotation.Log;
import com.iims.common.core.controller.BaseController;
import com.iims.common.core.domain.AjaxResult;
import com.iims.common.core.page.TableDataInfo;
import com.iims.common.enums.BusinessType;
import com.iims.finance.domain.CmisCwIncomeAffirm;
import com.iims.finance.service.ICmisCwIncomeAffirmService;
import com.iims.finance.vo.resp.CmisCwIncomeAffirmDetailVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author fanpei
 * @date 2021/7/7 14:17
 */
@Api(tags = "K-收入确认管理")
//@ApiSort(13)
@RestController
@RequestMapping("/business/incomeAffirm")
public class IncomeAffirmController extends BaseController {

    @Autowired
    private ICmisCwIncomeAffirmService incomeAffirmService;

    /**
     * 获取收入确认列表
     */
    @ApiOperation(value = "分页查询收入确认列表", response = CmisCwIncomeAffirmDetailVo.class)
    @ApiImplicitParams({
            @ApiImplicitParam(value = "当前记录起始索引(从1开始)", name = "pageNum", paramType = "query", required = true),
            @ApiImplicitParam(value = "每页显示记录数（>0）", name = "pageSize", paramType = "query", required = true),
            @ApiImplicitParam(value = "排序列", name = "orderByColumn", paramType = "query"),
            @ApiImplicitParam(value = "升降序方式：0升序 1降序", name = "isAsc", paramType = "query"),
            @ApiImplicitParam(value = "创建开始时间:format = \"yyyy-MM-dd\"", name = "beginTime", paramType = "query"),
            @ApiImplicitParam(value = "创建结束时间:format = \"yyyy-MM-dd\"", name = "endTime", paramType = "query"),
            @ApiImplicitParam(value = "审核状态,值来源于字典business_common_reviewStatus", name = "reviewStatus", paramType = "query"),
            @ApiImplicitParam(value = "收入确认人:模糊匹配", name = "affirmUserCN", paramType = "query"),
            @ApiImplicitParam(value = "审核人:模糊匹配", name = "reviewerCN", paramType = "query"),
    })
    @PreAuthorize("@ss.hasPermi('business:incomeAffirm:list')")
    @GetMapping("/list")
    public TableDataInfo list(@ApiIgnore CmisCwIncomeAffirm incomeAffirm) throws Exception {
        startPage();
        setSearchTimeRange(incomeAffirm);
        setSeqNumPageSizeStart(incomeAffirm);
        return getDataTable(incomeAffirmService.getCwIncomeAffirmList(incomeAffirm));
    }

    @ApiOperation(value = "获取 [合同] 所属收入确认列表", response = CmisCwIncomeAffirmDetailVo.class)
    @GetMapping("/listByContract/{contractId}")
    public AjaxResult listByContract(@ApiParam(value = "正式合同Id", required = true) @PathVariable Long contractId) {
        return AjaxResult.success(incomeAffirmService.getContractCwIncomeAffirmList(contractId));
    }

    /**
     * 根据收入确认编号获取详细信息
     */
    @ApiOperation(value = "根据收入确认Id获取详细信息", response = CmisCwIncomeAffirmDetailVo.class)
    @ApiImplicitParam(name = "affirmId", value = "收入确认Id", paramType = "path", required = true)
    @PreAuthorize("@ss.hasPermi('business:incomeAffirm:query')")
    @GetMapping(value = "/{affirmId}")
    public AjaxResult getInfo(@PathVariable Long affirmId) {
        return AjaxResult.success(incomeAffirmService.getCwIncomeAffirmDetailById(affirmId));
    }

    /**
     * 新增收入确认
     */
    @ApiOperation(value = "新增收入确认")
    @ApiOperationSupport(ignoreParameters = {"affirmId", "reviewer", "reviewStatus", "reviewTime", "reviewerCN", "affirmUserCN"})
    @PreAuthorize("@ss.hasPermi('business:incomeAffirm:add')")
    @Log(title = "新增收入确认", businessType = BusinessType.INSERT)
    @Transactional
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CmisCwIncomeAffirm incomeAffirm) {
        incomeAffirmService.insertCwIncomeAffirm(incomeAffirm);
        return AjaxResult.success();
    }

    /**
     * 修改收入确认
     */
    @ApiOperation("修改收入确认")
    @PreAuthorize("@ss.hasPermi('business:incomeAffirm:edit')")
    @ApiOperationSupport(ignoreParameters = {"reviewer", "reviewStatus", "reviewTime", "reviewerCN", "affirmUserCN"})
    @Log(title = "修改收入确认", businessType = BusinessType.UPDATE)
    @Transactional
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CmisCwIncomeAffirm incomeAffirm) {
        incomeAffirmService.updateCwIncomeAffirm(incomeAffirm);
        return AjaxResult.success();
    }

    /**
     * 删除收入确认
     */
    @ApiOperation("删除收入确认")
    @PreAuthorize("@ss.hasPermi('business:incomeAffirm:remove')")
    @Log(title = "删除收入确认", businessType = BusinessType.DELETE)
    @Transactional
    @DeleteMapping("/{affirmId}")
    public AjaxResult remove(@ApiParam("收入确认Id") @PathVariable Long affirmId) {
        incomeAffirmService.deleteById(affirmId);
        return AjaxResult.success();
    }
}
